//
//  HELPDFfileCacheTool.m
//  sanda
//
//  Created by wsj2015 on 16/7/20.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELPDFfileCacheTool.h"

@implementation HELPDFfileCacheTool


+(NSString *)isChchedWithPdfFilename:(NSString *)pdfName{

    
    NSFileManager *fm = [NSFileManager defaultManager];
    //huo
    //    NSString *fileName =[[NSUserDefaults standardUserDefaults] objectForKey:self.pdfNameShow];
    NSString *home = NSHomeDirectory();
    NSString *documentsPath = [home stringByAppendingPathComponent:@"Documents"];
    NSString *filePath =[documentsPath stringByAppendingPathComponent:pdfName];
    
    if ([fm fileExistsAtPath:filePath]) {
       
        return  filePath;
    }
    return nil;
}

+ (NSString *)getDownloadPathWithPdfName:(NSString *)pdfName{
    NSString *home = NSHomeDirectory();
    NSString *documentsPath = [home stringByAppendingPathComponent:@"Documents"];
    NSString *downloadURL =[documentsPath stringByAppendingPathComponent:pdfName];
    return downloadURL;
}



+ (NSNumber *)getLastPageFromKey:(NSString *)pdfKey{

 return  [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",pdfKey,HEL_USERID]];
}
+ (void)saveLastPage:(NSInteger)page withPdfKey:(NSString *)pdfKey
{
    [[NSUserDefaults standardUserDefaults] setObject:@(page) forKey:[NSString stringWithFormat:@"%@%@",pdfKey,HEL_USERID]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


+ (void)removePdfFileWithPdfNames:(NSArray<NSString *>*)pdfNames{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [pdfNames enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           NSString *path = [HELPDFfileCacheTool getDownloadPathWithPdfName:obj];
            if (path) {
                NSFileManager *fm = [NSFileManager defaultManager];
                [fm removeItemAtPath:path error:nil];
            }
        }];
    });
  
  
    
}








@end
